package com.huawei.bitfun;

import com.huawei.bitfun.bean.DocumentBean;

import java.util.*;

public class OptimizeManager {
    private final Map<String, Set<DocumentBean>> documentMap = new HashMap<>();

    private OptimizeManager() {}

    public static OptimizeManager getInstance() {
        return InstanceHolder.INSTANCE;
    }

    public void addDocumentBean(DocumentBean documentBean) {
        var fileName = documentBean.getFile();
        if (!documentMap.containsKey(fileName)) {
            documentMap.put(fileName, new HashSet<>());
        }
        documentMap.get(fileName).add(documentBean);
    }

    public void addAllDocumentBean(List<DocumentBean> documentBeans) {
        for (DocumentBean documentBean : documentBeans) {
            addDocumentBean(documentBean);
        }
    }

    public Set<DocumentBean> getDocumentBeans(String fileName) {
        return documentMap.get(fileName);
    }

    public boolean hasOptimizeFile(String fileName) {
        return documentMap.containsKey(fileName);
    }

    private static final class InstanceHolder {
        public static final OptimizeManager INSTANCE = new OptimizeManager();
    }
}